package com.mx.contror;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.google.gson.Gson;
import com.mx.entity.Person;
import com.mx.entity.TestAjax;

@Controller
public class AjaxTestController {
	@Resource
	HttpServletResponse response;
	//注入我们的service
   @RequestMapping("/testAjaxdata")
   @ResponseBody
   public   Map getajax(int page, int rows){
	   System.out.println("ajax");
	   Map<Person, Person>  map=new  HashMap<Person, Person>();
	   TestAjax  ajax1=new TestAjax(1,"zhangsan",25.6);
	   TestAjax  ajax2=new TestAjax(2,"lisi",895.6);
	   TestAjax  ajax3=new TestAjax(3,"zhangsan2",1251.6);
	   TestAjax  ajax4=new TestAjax(4,"zhangsan3",125.6);
	   List<TestAjax>  list=new ArrayList<TestAjax>();
	   list.add(ajax1);
	   list.add(ajax2);
	   list.add(ajax3);
	   list.add(ajax4);
	   Map resultmap=new HashMap();
	   resultmap.put("rows", list);
	   resultmap.put("total", list.size());
	   return resultmap;
   }
   //通过id找到我们的数据
   @RequestMapping("/findajax")
   @ResponseBody
   public String getById(@RequestParam String id){
	   int id1=Integer.parseInt(id);
	   TestAjax  ajax1=new TestAjax(1,"文件下载一",25.6);
	   TestAjax  ajax3=new TestAjax(2,"文件下载二",1251.6);
	   TestAjax  ajax2=new TestAjax(3,"文件下载三",1251.6);
	   TestAjax  ajax4=new TestAjax(4,"文件下载四",1251.6);
	   TestAjax  ajax5=new TestAjax(5,"文件下载五",1251.6);
	   TestAjax  ajax6=new TestAjax(6,"文件下载六",1251.6);
	   List<TestAjax>  list=new ArrayList<TestAjax>();
	   list.add(ajax1);
	   list.add(ajax3);
	   list.add(ajax2);
	   list.add(ajax4);
	   list.add(ajax5);
	   list.add(ajax6);
	   Gson  gson=new  Gson();
		 String  list1= gson.toJson(list);
	   return list1;
   }
   @RequestMapping("/handleRequestInternal")
   public ModelAndView handleRequestInternal(){
	        Map<String,Object>  model = new HashMap<String,Object>();  
	        
	            model.put("courtName","qqq");  
	            model.put("reservations","AAA");  
	       
	        return new ModelAndView("c",model);  
	    } 
}
